package me.zingon.WebSocket.model;

import me.zingon.WebSocket.tools.Players;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * Created by ZTC on 12/19/2016.
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class Bullet extends BaseModel implements Runnable {

    @Autowired
    Players players;

    int id;
    String ower; //session id

    public Bullet(@Value("${bullet.width}") int width,
                  @Value("${bullet.height}") int height,
                  @Value("${screen.x}")int screenX,
                  @Value("${screen.y}")int screenY){
        this.width=width;
        this.height=height;
        this.screenX=screenX;
        this.screenY=screenY;
        this.isAlive=true;
    }

    public void run() {
        if (this.direct.equals("W")) {
            this.y -= this.speed;
        } else if (this.direct.equals("D")) {
            this.x += this.speed;
        } else if (this.direct.equals("A")) {
            this.x -= this.speed;
        } else if (this.direct.equals("S")) {
            this.y += this.speed;
        }
        if (this.x < 0 || this.x > screenX || this.y < 0 || this.y > screenY) {
            players.rmBullet(this);
        }
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getOwer() {
        return ower;
    }

    public void setOwer(String ower) {
        this.ower = ower;
    }
}
